<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="__STATIC__/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="__STATIC__/css/font.css">
    <link rel="stylesheet" href="__STATIC__/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="__STATIC__/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__STATIC__/js/xadmin.js"></script>
    <style>
        .icon-list{
            display: none;width: 60%;
            height: 220px;
            background-color: #ffffff;
            position: fixed;
            z-index: 999;
            overflow: auto;
            bottom: 40px;
            left: 18%;
        }
        .icon-item{
            border:1px solid #e2e2e2;
            display: inline;
            height: auto;width: 40px;float: left;
            text-align: center;
        }
        .icon-item:hover
        {
            background-color:#999999;
        }
    </style>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-body">
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">
                菜单名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="username" name="menu_name" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$info.menu_name}">
                <input type="hidden" name="id" value="{$info.id}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                父级菜单
            </label>
            <div class="layui-input-inline">
                <select name="pid" lay-verify="required">
                    <option value="0">请选择</option>
                    {volist name="one" id="vo"}
                    <option value="{$vo.id}" {$info.pid==$vo.id?"selected":""}>{$vo.menu_name}</option>
                    {/volist}
                </select>
            </div>
            <div class="layui-form-mid layui-word-aux">
                一级菜单留空不选
            </div>
        </div>
        <div class="layui-form-item">
            <label  class="layui-form-label">
                controller
            </label>
            <div class="layui-input-inline">
                <input type="text" name="controller" required="" value="{$info.controller}"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                action
            </label>
            <div class="layui-input-inline">
                <input type="text" name="action" required="" value="{$info.action}"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                排序
            </label>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="number" name="sort" required="" value="{$info.sort}"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                图标
            </label>
            <div id="iconSelected" class="layui-input-inline" style="width: 40px;padding-top: 10px;">
                <i class="layui-icon {$info.icon}"></i>
                <input type="hidden" name="icon" value="{$info.icon}">
            </div>
            <div class="layui-input-inline" style="width: 40px;padding-top: 8px;">
                <div class="layui-btn layui-btn-xs" id="icon">
                    <i class="layui-icon layui-icon-down"></i>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                类型
            </label>
            <div class="layui-input-block">
                <input type="radio" name="type" lay-skin="primary" value="1" title="菜单" {$info.type==1?"checked":""}>
                <input type="radio" name="type" lay-skin="primary" value="0" title="按钮" {$info.type==0?"checked":""}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                状态
            </label>
            <div class="layui-input-block">
                <input type="radio" name="status" lay-skin="primary" value="1" title="启用" {$info.status==1?"checked":""}>
                <input type="radio" name="status" lay-skin="primary" value="0" title="禁用" {$info.status==0?"checked":""}>
            </div>
        </div>
        <div class="layui-form-item" style="padding-top: 60px;">
            <label  class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="add" lay-submit="">
                保存
            </button>
        </div>
    </form>
</div>
<div class="icon-list" >
    <div style="width: 94%;margin: 2%;">
        {volist name="icon" id="vo"}
        <div class="icon-item">
            <i class="layui-icon {$vo.icon}" style="font-size: 30px;"></i>
        </div>
        {/volist}
    </div>
</div>
<script>
    layui.use(['form','layer'], function(){
        var form = layui.form
            ,layer = layui.layer;
        //监听提交
        form.on('submit(add)', function(data){
            //发异步，把数据提交给php
            console.log(data.field);
            $.post('{:url("Admin/menuEdit")}',data.field,function (res) {
                if (res.code == 1){
                    layer.msg(res.msg, {icon: 6,time:1000},function () {
                        // 获得frame索引
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.layer.close(index);
                    });
                }else {
                    layer.msg(res.msg, {icon: 5,time:3000});
                }
            });
            return false;
        });
        $(document).on('click','.icon-item',function () {
            var css = $(this).children().attr("class");
            $("#iconSelected>i").remove();
            $("#iconSelected").children('input[name="icon"]').val('');
            $("#iconSelected").prepend('<i class="'+ css +'" style="font-size: 18px;"></i>');
            $("#iconSelected").children('input[name="icon"]').val(css.substring(css.indexOf(' ')));
            form.render();
        });
    });

    $("#icon").on('click',function () {
        if ($('.icon-list').css("display")=="none"){
            $('.icon-list').show();
        }else {
            $('.icon-list').hide();
        }
    });
</script>

</body>

</html>